package com.mlm.mlmapp.wxapi;






import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.mlm.mlmapp.cons.Constants;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{
	
	private static final String TAG = "XPayEntryActivity";
	
    private IWXAPI api;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.pay_result);
        
    	api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);
        api.handleIntent(getIntent(), this);
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}
	public static final  String PAY_FINISH="com.mlm.mlmapp.wxpay.finish";
	public static final String WECHAT_PAY_SUCCESS="0";
	public static final String WECHAT_PAY_FAILURE="1";
	public static final String ALI_PAY_SUCCESS="2";
	public static final String ALI_PAY_FAILURE="3";

	@Override
	public void onResp(BaseResp resp) {
	String state="";
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {

			if(resp.errCode==0){
				state=WECHAT_PAY_SUCCESS;

			}else{
				state=WECHAT_PAY_FAILURE;
			}
			Intent intent = new Intent();
			intent.setAction(PAY_FINISH);
			intent.putExtra("state", state);
			this.sendOrderedBroadcast(intent, null);
		}
		this.finish();
	}
}